package it.pride.primefacesShowcase.controller;

import it.pride.primefacesShowcase.model.User;
import org.primefaces.model.SelectableDataModel;

import javax.faces.model.ListDataModel;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: eluibon
 * Date: 01/02/12
 * Time: 14.18
  */
public class UsersDataModel extends ListDataModel<User> implements SelectableDataModel<User> {

    @Override
    public Object getRowKey(User user) {
        return user.getId() ;
    }

    @Override
    public User getRowData(String rowKey) {
           
        List<User> Users = (List<User>) getWrappedData();
          
        for(User user : Users) {
            if(user.getId().toString().equals(rowKey))
                return user;
        }

        return null;  
    }
}
